Skip to content

Conversation

@Haimasker
Copy link

  • Consistent function parameters definition

  • Rule is disabled by default

  • Possible types of preferred function parameters are: "Inline", "ParamBlock"

PR Summary

This PSScriptAnalyzer rule enforces uniform parameter definitions ("Inline" or "ParamBlock") across functions, improving code readability and maintainability.

Key Benefits:

  1. Consistency: Standardizes parameter style project-wide, making code easier to read and extend.
  2. Advanced Attributes: param block provides CmdletBinding(), OutputType(), and other advanced attributes. On the other hand, these attributes can be blocked by using inline parameters.

PR Checklist

* Consistent function parameters definition

* Rule is disabled by default

* Possible types of preferred function parameters are: "Inline",
"ParamBlock"
@Haimasker
Copy link
Author

@microsoft-github-policy-service agree

@Haimasker
Copy link
Author

@sdwheeler @michaeltlombardi @bergmeister
Sorry for additional tagging, but when a merge request review can be expected?

Thank you in advance.

Copy link
Collaborator

@bergmeister bergmeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution and sorry for late review. I added Andy as well as he is the main code owner.
The rule might be a bit controversial as for some folks there is no 'correct' kind, therefore I suggest to name rule UseConsistentParametersKind for consistency with other rule names

| [UseConsistentIndentation](./UseConsistentIndentation.md) | Warning | No | Yes |
| [UseConsistentWhitespace](./UseConsistentWhitespace.md) | Warning | No | Yes |
| [UseCorrectCasing](./UseCorrectCasing.md) | Information | No | Yes |
| [UseCorrectParametersKind](./UseCorrectParametersKind.md) | Warning | No | Yes |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please align the | with the other lines


Rewrite function so it defines parameters as specified in the rule

## Example
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think also adding an incorrect example would be useful


## Description

All functions should have same parameters definition kind specified in the rule. Either using inline parameters in function definition or using param() block inside function body.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would try to better highlight there are only 2 kinds and what the consequences are of mixing them (is it just optical or does one get a compile or runtime error?).

Also, just talking from personal preference: I mix them because if I just need a simple function with arguments that are small enough to fit in one line, then I like the inline option but the moment things get more complicated (e.g. adding attributes/types, which makes inline hard to read), I use param block. We can definitely add this rule as-is since people can enable it if they think it's useful but just wondering whether it would be useful to some folks to have an optional configuration that allows them to enforce using param block when certain criteria are met (e.g. number of params, presence of attributes, etc.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants